# 14.使用模板
import uvicorn
from fastapi import FastAPI
from starlette.requests import Request
from starlette.responses import HTMLResponse
from starlette.templating import Jinja2Templates

app = FastAPI()
templates = Jinja2Templates(directory="templates")


# 装饰器
@app.get("/books/{book_id}", response_class=HTMLResponse)
def get_book_by_id(book_id, request: Request):
    return templates.TemplateResponse(name="book.html",
                                      context={"request": request,
                                               "book_name": 'Python从小白到大牛',
                                               'author': '关东升',
                                               'id': book_id})



if __name__ == "__main__":
    uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=True)
